$(document).ready(function(){
	//alert(H.APP+'admin.php');
	H.load("internetFunction","app/admin/");
	var netId = 'adminInternet';
	var tabs = '#getInternet,#setInternet';
	inter.pageInit();
	H.menu('',netId,tabs)
	H.load("encrypt");
	//tableInternet("#getInternet");
	//$("#getInternet").html(tableInternet());
	$('input[name="date"]').datepicker({dateFormat:'yy-mm-dd'});
	$("#navi-getInternet").click(function(){
		$("#getInternet").html(tableInternet());
		H.session('internetFmt','table');
		H.menu('#getInternet',netId,tabs);
		/*$("#setInternet").hide();
		$("#getInternet").show();*/
	});
	$("#navi-getIntUl").click(function(){
		var xhtml = '<p class="ulSetBars"><a href="javascript:void(0);" id="setUlCss">样式固定</a> <a href="javascript:void(0);" id="autoUlCss">样式自动</a></p>';
		xhtml += ulsInternet();
		$("#getInternet").html(xhtml);
		H.session('internetFmt','ul');
		H.menu('#getInternet',netId,tabs);
		/*$("#setInternet").hide();
		$("#getInternet").show();*/
	});
	$("#navi-setInternet").click(function(){
		/*$("#getInternet").hide();
		$("#setInternet").show();*/
		H.menu('#setInternet',netId,tabs);

	});
	//	保存“提交”
	$("#toSave").click(function(){
		//alert(H.checked("checked"));return;
		//console.log(H.checked("checked"));return;
		if(H.checked("checked","alert")) return;
		var formData = H.toJson($("#setInternet").serializeArray());
		formData["explan"] = $("#explan").val();//var formData = H.toJson($("#setInternet").serializeArray()); 无法获取explan的值
		//console.log(formData);return;
		if(!H.empty(formData["username"])){
			formData["username"] = B.encode(formData["username"]);
		}
		if(!H.empty(formData["passw"])){
			formData["passw"] = B.encode(formData["passw"]);
		}
		if(!H.empty(formData["email"])){
			formData["email"] = B.encode(formData["email"]);
		}
		if(!H.empty(formData["cellphone"])){
			formData["cellphone"] = B.encode(formData["cellphone"]);
		}
		$.post(H.APP+'admin/admin.php',{item:"setInternet",internet:formData,model:"internet",uid:Math.random()},
			function(data){
				alert(data);
		});
		H.delStorage("internet");//保存成功后自动清空本地数据
	});
	$("#navi-delInternet").click(function(){
		if(H.delStorage("internet")){
			alert("清除成功！！");
			window.location.reload();
		}
	});
	//$("#console").load(H.APP+'admin.php',{model:"internet",uid:Math.random()});
	/*
	tinymce.init({
		selector:'textarea#explan'
	});
	*/
	//$("#explan").markItUp(mySettings);
	$("#explanTip").click(function(){
		
		$("#dialog").dialog({
				title:"[ 详情 ] 输入框",
				width:500,
				modal:true,
				//height:500,
				buttons:[{
					text:"确定",
					click:function(){
						var text = $("#explan").val();
						$("#explanText").html(text);
						$(this).dialog("close");
					}		
				}]
		});
	});

});

$(document).on("change",".exsafe",function(){
	var ckbId = $(this).attr("id");
	var k = $("#"+ckbId+ ":checked").val();
	var usersSafe = $("#uersSafe-"+k).text();
	var psswSafe = $("#psswSafe-"+k).text();
	var emailSafe = $("#emailSafe-"+k).text();
	var cellSafe = $("#cellSafe-"+k).text();
	if(H.empty(k)){
			$("#getInternet").html(tableInternet());
			return;
	}else{
			if(usersSafe)
				$("#uersSafe-"+k).text(B.decode(usersSafe));
			if(psswSafe)
				$("#psswSafe-"+k).text(B.decode(psswSafe));
			if(emailSafe)
				$("#emailSafe-"+k).text(B.decode(emailSafe));
			if(cellSafe)
				$("#cellSafe-"+k).text(B.decode(cellSafe));
	}
});

$(document).on("click",".disExplanA",function(){
	var cont = $(this).attr("_cont");
	if(H.empty(cont))
		return;
	$("#console").html(cont);
	$("#console").dialog();
});

//设置ul显示下的--样式固定
$(document).on("click","#setUlCss",function(){
	var adIntsetUlCss = {};//admin_internet_setUlCss
	adIntsetUlCss['.toNetHref'] = {'color':$('.toNetHref').css('color')};
	adIntsetUlCss['#ulsInternet'] = {'background':$('#ulsInternet').css('background-color')};
	//alert($('#ulsInternet').css('background'));//jquery 获取背景样式失败
	//alert(H.json2str(adIntsetUlCss));
	H.local('adIntsetUlCss',H.json2str(adIntsetUlCss));
});
//设置ul显示下的--样式自动
$(document).on("click","#autoUlCss",function(){
	H.local('adIntsetUlCss','');
	inter.atuoUlCss();
});
var inter = {
		//页面初始化	2016/4/8 星期五
	pageInit: function()
	{
		//数据显示模式设置
		var dataFmt = H.session('internetFmt');
		if(dataFmt == 'ul'){this.ulsEnv();}
		else{$("#getInternet").html(tableInternet());}
		this.atuoUlCss();
	},
		//ul模式下样式自动处理	2016/4/8 星期五
	atuoUlCss: function()
	{
		var adIntsetUlCss = H.local('adIntsetUlCss');
		if(H.empty(adIntsetUlCss)){
			$('.toNetHref').css({"color":H.randColHex()});
			$('#ulsInternet').css({"background":H.randColHex()});
		}else{
			var UlCss = $.parseJSON(adIntsetUlCss);
			for(var k in UlCss){$(k).css(UlCss[k]);}
		}
	},
		//uls 显示模式	2016/4/8 星期五
	ulsEnv: function()
	{
		var xhtml = '<p class="ulSetBars"><a href="javascript:void(0);" id="setUlCss">样式固定</a> <a href="javascript:void(0);" id="autoUlCss">样式自动</a></p>';
		xhtml += ulsInternet();
		$("#getInternet").html(xhtml);
	}
};